/*
 * @lc app=leetcode.cn id=160 lang=javascript
 *
 * [160] 相交链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} headA
 * @param {ListNode} headB
 * @return {ListNode}
 */
var getIntersectionNode = function(headA, headB) {
    let nowA = headA
    let nowB = headB
    let intersection = null
    for(;nowA;){
        for(;nowB;) {
            if (nowB === nowA) {
                intersection = nowA
                break
            }
            nowB = nowB.next
        }
        if (intersection) {
            break
        }
        nowB = headB
        nowA = nowA.next
    }
    return intersection
};
// @lc code=end

